package org.example;

import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * @Title : retry
 * @Description: :
 * @author: libo@juzishuke.com
 * @date: 2023/10/19 13:38
 * @Version:1.0
 */
@Service
@Slf4j
public class DoRetryService {
    private AtomicInteger ai = new AtomicInteger(0);
    @Retryable(value = Exception.class, maxAttempts = 4, backoff = @Backoff(delay = 2000L, multiplier = 1.5))
    public boolean doRetry(boolean isRetry) throws Exception {
        ai.addAndGet(1);
        log.info("开始通知下游系统");
        log.info("通知下游系统");
        if (isRetry) {
            throw new RuntimeException("通知下游系统异常");
        }
        return true;
    }
    @Recover()
    public boolean recover(boolean isRetry)throws Exception{
        return false;
    }

    @Recover()
    public boolean recover2(boolean isRetry)throws Exception{
        return false;
    }

}
